#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QPushButton>
#include <QMessageBox>
#include "handler.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->init();


    //开始按钮
    connect(this->ui->btn_start,&QPushButton::clicked,this->scene,&GraphicsScene::startGame);
    connect(this->ui->btn_suspend,&QPushButton::clicked,this->scene,&GraphicsScene::suspendGame);
    connect(this->ui->btn_stop,&QPushButton::clicked,this,&MainWindow::stopGame);


    Handler *handler = Handler::getInstance();
    connect(handler,&Handler::beatMouse,this,[=](){
        this->score+=10;
        this->ui->lcdNumber->display(this->score);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::stopGame()
{
    this->scene->stopGame();
    this->ui->lcdNumber->display(0);
}
void MainWindow::init()
{
    //初始化界面
    this->scene = new GraphicsScene;
    this->ui->graphicsView->setScene(scene);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
    int ret = QMessageBox::question(this,"提醒","是否关闭？","确定","取消");
    if(ret==1)
    {
        event->ignore();
    }
}
